<!--地址列表-->
<template>
    <div>
        <van-nav-bar
                title="收货地址列表页"
                placeholder
                fixed
                left-arrow
                @click-left="goBack"
        />
        <van-address-list
                v-model="chosenAddressId"
                :list="list"
                default-tag-text="默认"
                @add="onAdd"
                @edit="onEdit"
        />
    </div>
</template>

<script>
    export default {
        data() {
            return {
                name:"",
                chosenAddressId: "1",
                list: [
                ],
            };
        },
        created() {
            this.mounted();
        },
        methods: {
            goBack() {
                this.$router.go(-1);
            },
            onAdd(userId) {
                this.$router.push({
                    path: '/Addaddress',
                    name: 'Addaddress',
                    query:{
                        userId:userId
                    }
                });
            },
            //点击编辑传地址id给地址编辑，以便地址回显
            onEdit(item, index) {
                let id = this.list[index].id;
                this.$router.push(`Addddress?id=${id}`);
            },
            mounted() {
                this.$http.post("/address/findAllAddress").then(result=>{
                    console.log(result.data.data[0].userId)
                    result.data.data.forEach(item=>{
                        item.address=item.province+item.city+item.county+item.addressDetail
                    })

                    this.list=result.data.data;
                    if (this.list.length!=0){
                        this.chosenAddressId=this.list[0].id;
                    }
                    console.log(this.list);
                })
            },
        },
    };
</script>
 
 